from rest_framework import serializers

from . import models


def my_validators(value):
    if value.startswith('user'):
        raise serializers.ValidationError('标题包含敏感字符')
    return value


class UserInfoSerializer(serializers.ModelSerializer):

    username = serializers.CharField(max_length=32, validators=[my_validators], error_messages={'blank': '必填项'})

    class Meta:
        # depth = 0
        model = models.UserInfo
        fields = ['username', 'password']